﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ISHotel.Database;

namespace ISHotel.presentation
{
    public partial class StravovaniForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonVlozStravovani_Click(object sender, EventArgs e)
        {
            Stravovani newStravovani = new Stravovani();
            newStravovani.nazev_stravovani = TextBoxNazev.Text;
            newStravovani.cena_stravovani = Convert.ToInt32(TextBoxCena.Text);

            StravovaniTable addSourceRecord = new StravovaniTable();
            addSourceRecord.Insert(newStravovani);

            Response.Redirect(Request.RawUrl);
        }

        public void button_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "DeleteStravovani")
            {
                StravovaniTable delSourceRecord = new StravovaniTable();
                try
                {
                    delSourceRecord.Delete(Convert.ToInt32(e.CommandArgument));
                }
                catch (Exception ex)
                {
                    LabelErr.Text = "Stravování nelze smazat, je již obsaženo v objednávkách.";
                }
                if (LabelErr.Text == "")
                {
                    Response.Redirect(Request.RawUrl);
                }
            }
        }

        protected void StravovaniDetail_OnUpdated(object sender, EventArgs e)
        {
            GridViewStravovani.DataBind();
            DetailsView1.DataBind();
        }
    }
}